package com.csmz.enterprise.service.impl;

import com.csmz.common.utils.DateUtils;
import com.csmz.common.utils.SecurityUtils;
import com.csmz.enterprise.domain.CsmzHbhPeopleList;
import com.csmz.enterprise.domain.CsmzParttimeRegistrationPerson;
import com.csmz.enterprise.mapper.CsmzHbhPeopleListMapper;
import com.csmz.enterprise.mapper.CsmzParttimeRegistrationPersonMapper;
import com.csmz.enterprise.service.ICsmzParttimeRegistrationPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 报名人员Service业务层处理
 * 
 * @author TT
 * @date 2025-09-17
 */
@Service
public class CsmzParttimeRegistrationPersonServiceImpl implements ICsmzParttimeRegistrationPersonService 
{
    @Autowired
    private CsmzParttimeRegistrationPersonMapper csmzParttimeRegistrationPersonMapper;
    @Autowired
    private CsmzHbhPeopleListMapper csmzHbhPeopleListMapper;

    /**
     * 查询报名人员
     * 
     * @param id 报名人员主键
     * @return 报名人员
     */
    @Override
    public CsmzParttimeRegistrationPerson selectCsmzParttimeRegistrationPersonById(Long id)
    {
        return csmzParttimeRegistrationPersonMapper.selectCsmzParttimeRegistrationPersonById(id);
    }

    /**
     * 查询报名人员列表
     * 
     * @param csmzParttimeRegistrationPerson 报名人员
     * @return 报名人员
     */
    @Override
    public List<CsmzParttimeRegistrationPerson> selectCsmzParttimeRegistrationPersonList(CsmzParttimeRegistrationPerson csmzParttimeRegistrationPerson)
    {
        return csmzParttimeRegistrationPersonMapper.selectCsmzParttimeRegistrationPersonList(csmzParttimeRegistrationPerson);
    }

    /**
     * 新增报名人员
     * 
     * @param csmzParttimeRegistrationPerson 报名人员
     * @return 结果
     */
    @Override
    public int insertCsmzParttimeRegistrationPerson(CsmzParttimeRegistrationPerson csmzParttimeRegistrationPerson)
    {
        // 登录用户id
        Long userId = SecurityUtils.getUserId();
        csmzParttimeRegistrationPerson.setUserId(userId);
        List<CsmzParttimeRegistrationPerson> csmzParttimeRegistrationPeople = csmzParttimeRegistrationPersonMapper.selectCsmzParttimeRegistrationPersonList(csmzParttimeRegistrationPerson);
        if (!csmzParttimeRegistrationPeople.isEmpty()){
            return 4000;
        }
        // 初始化用户名单
        CsmzHbhPeopleList csmzHbhPeopleList = new CsmzHbhPeopleList();
        csmzHbhPeopleList.setUserId(userId);
        csmzHbhPeopleList.setListType(0);
        csmzHbhPeopleList.setReason("");
        csmzHbhPeopleListMapper.insertCsmzHbhPeopleList(csmzHbhPeopleList);
        csmzParttimeRegistrationPerson.setCreateTime(DateUtils.getNowDate());
        return csmzParttimeRegistrationPersonMapper.insertCsmzParttimeRegistrationPerson(csmzParttimeRegistrationPerson);
    }

    /**
     * 修改报名人员
     * 
     * @param csmzParttimeRegistrationPerson 报名人员
     * @return 结果
     */
    @Override
    public int updateCsmzParttimeRegistrationPerson(CsmzParttimeRegistrationPerson csmzParttimeRegistrationPerson)
    {
        csmzParttimeRegistrationPerson.setUpdateTime(DateUtils.getNowDate());
        return csmzParttimeRegistrationPersonMapper.updateCsmzParttimeRegistrationPerson(csmzParttimeRegistrationPerson);
    }

    /**
     * 批量删除报名人员
     * 
     * @param ids 需要删除的报名人员主键
     * @return 结果
     */
    @Override
    public int deleteCsmzParttimeRegistrationPersonByIds(Long[] ids)
    {
        return csmzParttimeRegistrationPersonMapper.deleteCsmzParttimeRegistrationPersonByIds(ids);
    }

    /**
     * 删除报名人员信息
     * 
     * @param id 报名人员主键
     * @return 结果
     */
    @Override
    public int deleteCsmzParttimeRegistrationPersonById(Long id)
    {
        return csmzParttimeRegistrationPersonMapper.deleteCsmzParttimeRegistrationPersonById(id);
    }

    /**
     *  查询我的兼职
     * @param csmzParttimeRegistrationPerson 报名人员
     * @return 结果
     */
    @Override
    public List<CsmzParttimeRegistrationPerson> selectCsmzMyParttimeList(CsmzParttimeRegistrationPerson csmzParttimeRegistrationPerson) {
        //  登录用户id
        Long userId = SecurityUtils.getUserId();
        csmzParttimeRegistrationPerson.setUserId(userId);
        return csmzParttimeRegistrationPersonMapper.selectCsmzMyParttimeList(csmzParttimeRegistrationPerson);
    }
}
